Purpose

The purpose of this analysis document is to ensure the reproducability of the results by guiding the reader through the random forest analysis of the factors associated with the health of western redcedar.

Approach

Root data were shared by citizen scientists in the Wester Redcedar Dieback Map project on iNaturalist.

All of the data used in the below analyses are described in the Data Wrangle folder.

Limitations

Next steps

Data

The data used in the below visualizations are described in the Data Wrangle folder.

All tree health categories

## # A tibble: 11 x 2
## # Groups:   field.tree.canopy.symptoms [11]
##    field.tree.canopy.symptoms                             n
##    <fct>                                              <int>
##  1 Branch Dieback or 'Flagging'                          19
##  2 Browning Canopy                                       19
##  3 Extra Cone Crop                                        2
##  4 Healthy                                              403
##  5 Multiple Symptoms (please list in Notes)              17
##  6 New Dead Top (red or brown needles still attached)    33
##  7 Old Dead Top (needles already gone)                   83
##  8 Other (please describe in Notes)                       8
##  9 Thinning Canopy                                      118
## 10 Tree is dead                                          37
## 11 Yellowing Canopy                                      10

Filter Data

We need to filter the data to only include response and explanatory variables we’re interested in. For example, whether a sound clip was included in the iNat data is not important.

We also need to remove other response variables like “field.percent.canopy.affected….” so it is not used as a predictor for tree health.

Note it might be interesting to know if the user was an important factor in predicting if the tree is healthy/unhealthy.

There are also a number of factors that should probably be removed because they may be biasing the data. For example, only trees with the ‘other factor’ question may only be answered for unhealthy trees. We need to think about this a bit more.

Impute data

We continue to get the below error, but were able to work around it by imputing the data.

Error in randomForest.default(m, y, …) : Need at least two classes to do classification.

To impute the data we have to remove factors with >53 levels.

The below code lists the number of levels for the variables that are factors.

  • The following factors had more than 53 levels
    • “muaggatt_musym”
    • “muaggatt_muname”
    • “component_compname”
    • “component_geomdesc”
    • “component_taxclname”
    • “component_taxsubgrp”

Imputed data table

## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  46.46% 94.74% 94.74%100.00% 16.38% 88.24% 87.88% 74.70%100.00% 72.03% 94.59%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.66% 94.74% 94.74%100.00% 15.14% 82.35% 87.88% 74.70%100.00% 73.73% 89.19%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  46.33% 94.74% 94.74%100.00% 15.14% 76.47% 87.88% 75.90%100.00% 75.42% 97.30%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.66% 94.74%100.00%100.00% 14.89% 82.35% 87.88% 73.49%100.00% 72.88% 94.59%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  45.39% 94.74% 94.74%100.00% 15.14% 82.35% 87.88% 72.29%100.00% 73.73% 89.19%100.00%
## ntree      OOB      1      2      3      4      5      6      7      8      9     10     11
##   300:  46.06%100.00% 94.74%100.00% 15.63% 70.59% 87.88% 75.90%100.00% 74.58% 89.19%100.00%

Train and test data

Model

## 
## Call:
##  randomForest(formula = field.tree.canopy.symptoms ~ ., data = training,      ntree = 2001, importance = TRUE, proximity = TRUE, na.action = na.omit) 
##                Type of random forest: classification
##                      Number of trees: 2001
## No. of variables tried at each split: 23
## 
##         OOB estimate of  error rate: 43.85%
## Confusion matrix:
##                                                    Branch Dieback or 'Flagging'
## Branch Dieback or 'Flagging'                                                  0
## Browning Canopy                                                               0
## Extra Cone Crop                                                               0
## Healthy                                                                       2
## Multiple Symptoms (please list in Notes)                                      0
## New Dead Top (red or brown needles still attached)                            0
## Old Dead Top (needles already gone)                                           1
## Other (please describe in Notes)                                              0
## Thinning Canopy                                                               1
## Tree is dead                                                                  0
## Yellowing Canopy                                                              0
##                                                    Browning Canopy
## Branch Dieback or 'Flagging'                                     0
## Browning Canopy                                                  0
## Extra Cone Crop                                                  0
## Healthy                                                          1
## Multiple Symptoms (please list in Notes)                         1
## New Dead Top (red or brown needles still attached)               2
## Old Dead Top (needles already gone)                              0
## Other (please describe in Notes)                                 0
## Thinning Canopy                                                  0
## Tree is dead                                                     2
## Yellowing Canopy                                                 0
##                                                    Extra Cone Crop Healthy
## Branch Dieback or 'Flagging'                                     0       9
## Browning Canopy                                                  0       5
## Extra Cone Crop                                                  0       1
## Healthy                                                          0     267
## Multiple Symptoms (please list in Notes)                         0       6
## New Dead Top (red or brown needles still attached)               0      12
## Old Dead Top (needles already gone)                              0      25
## Other (please describe in Notes)                                 0       7
## Thinning Canopy                                                  0      39
## Tree is dead                                                     0      12
## Yellowing Canopy                                                 0       5
##                                                    Multiple Symptoms (please list in Notes)
## Branch Dieback or 'Flagging'                                                              0
## Browning Canopy                                                                           0
## Extra Cone Crop                                                                           0
## Healthy                                                                                   1
## Multiple Symptoms (please list in Notes)                                                  4
## New Dead Top (red or brown needles still attached)                                        0
## Old Dead Top (needles already gone)                                                       1
## Other (please describe in Notes)                                                          0
## Thinning Canopy                                                                           1
## Tree is dead                                                                              0
## Yellowing Canopy                                                                          0
##                                                    New Dead Top (red or brown needles still attached)
## Branch Dieback or 'Flagging'                                                                        0
## Browning Canopy                                                                                     2
## Extra Cone Crop                                                                                     0
## Healthy                                                                                             5
## Multiple Symptoms (please list in Notes)                                                            0
## New Dead Top (red or brown needles still attached)                                                  4
## Old Dead Top (needles already gone)                                                                 1
## Other (please describe in Notes)                                                                    0
## Thinning Canopy                                                                                     3
## Tree is dead                                                                                        4
## Yellowing Canopy                                                                                    1
##                                                    Old Dead Top (needles already gone)
## Branch Dieback or 'Flagging'                                                         3
## Browning Canopy                                                                      2
## Extra Cone Crop                                                                      1
## Healthy                                                                             10
## Multiple Symptoms (please list in Notes)                                             1
## New Dead Top (red or brown needles still attached)                                   1
## Old Dead Top (needles already gone)                                                 20
## Other (please describe in Notes)                                                     0
## Thinning Canopy                                                                     18
## Tree is dead                                                                         6
## Yellowing Canopy                                                                     0
##                                                    Other (please describe in Notes)
## Branch Dieback or 'Flagging'                                                      0
## Browning Canopy                                                                   0
## Extra Cone Crop                                                                   0
## Healthy                                                                           0
## Multiple Symptoms (please list in Notes)                                          0
## New Dead Top (red or brown needles still attached)                                0
## Old Dead Top (needles already gone)                                               0
## Other (please describe in Notes)                                                  0
## Thinning Canopy                                                                   0
## Tree is dead                                                                      0
## Yellowing Canopy                                                                  0
##                                                    Thinning Canopy Tree is dead
## Branch Dieback or 'Flagging'                                     2            0
## Browning Canopy                                                  0            2
## Extra Cone Crop                                                  0            0
## Healthy                                                         12            6
## Multiple Symptoms (please list in Notes)                         1            0
## New Dead Top (red or brown needles still attached)               3            2
## Old Dead Top (needles already gone)                             16            1
## Other (please describe in Notes)                                 0            0
## Thinning Canopy                                                 19            1
## Tree is dead                                                     3            1
## Yellowing Canopy                                                 2            0
##                                                    Yellowing Canopy class.error
## Branch Dieback or 'Flagging'                                      0   1.0000000
## Browning Canopy                                                   0   1.0000000
## Extra Cone Crop                                                   0   1.0000000
## Healthy                                                           1   0.1245902
## Multiple Symptoms (please list in Notes)                          0   0.6923077
## New Dead Top (red or brown needles still attached)                1   0.8400000
## Old Dead Top (needles already gone)                               0   0.6923077
## Other (please describe in Notes)                                  0   1.0000000
## Thinning Canopy                                                   1   0.7710843
## Tree is dead                                                      0   0.9642857
## Yellowing Canopy                                                  0   1.0000000

Concerns
  • Below are some concerns that should be investigated
  • The error rate is pretty high (~35%)
  • The MDS plots only represent a small percentage of the
Questions
  • Below are some questions to resolve moving forward
    • What is difference between MeanDecreaseAccuracy ad MeanDecreaseGini
      • MeanDecreaseAccuracy - how much the factor affected classification trees across, averaged for all 2000 trees?
      • MeanDecreaseGini - variation in influence of factor compared to other factors?

Explore different groupings

Five filtered Symptoms

Selected tree health categories

## # A tibble: 5 x 2
## # Groups:   field.tree.canopy.symptoms [5]
##   field.tree.canopy.symptoms                             n
##   <fct>                                              <int>
## 1 Healthy                                              403
## 2 New Dead Top (red or brown needles still attached)    33
## 3 Old Dead Top (needles already gone)                   83
## 4 Thinning Canopy                                      118
## 5 Tree is dead                                          37
Train and test data
Try creating random forest model from training data
## 
## Call:
##  randomForest(formula = field.tree.canopy.symptoms ~ ., data = training,      ntree = 2001, importance = TRUE, proximity = TRUE, na.action = na.omit) 
##                Type of random forest: classification
##                      Number of trees: 2001
## No. of variables tried at each split: 23
## 
##         OOB estimate of  error rate: 40%
## Confusion matrix:
##                                                    Healthy
## Healthy                                                269
## New Dead Top (red or brown needles still attached)      15
## Old Dead Top (needles already gone)                     29
## Thinning Canopy                                         51
## Tree is dead                                            10
##                                                    New Dead Top (red or brown needles still attached)
## Healthy                                                                                             4
## New Dead Top (red or brown needles still attached)                                                  2
## Old Dead Top (needles already gone)                                                                 3
## Thinning Canopy                                                                                     2
## Tree is dead                                                                                        2
##                                                    Old Dead Top (needles already gone)
## Healthy                                                                             12
## New Dead Top (red or brown needles still attached)                                   4
## Old Dead Top (needles already gone)                                                 15
## Thinning Canopy                                                                     13
## Tree is dead                                                                         2
##                                                    Thinning Canopy Tree is dead
## Healthy                                                         19            3
## New Dead Top (red or brown needles still attached)               3            1
## Old Dead Top (needles already gone)                             15            2
## Thinning Canopy                                                 15            5
## Tree is dead                                                     7            2
##                                                    class.error
## Healthy                                              0.1237785
## New Dead Top (red or brown needles still attached)   0.9200000
## Old Dead Top (needles already gone)                  0.7656250
## Thinning Canopy                                      0.8255814
## Tree is dead                                         0.9130435

Binary symptoms

Binary tree health categories

## # A tibble: 2 x 2
## # Groups:   field.tree.canopy.symptoms [2]
##   field.tree.canopy.symptoms     n
##   <fct>                      <int>
## 1 Healthy                      403
## 2 Unhealthy                    346
Train and test data
Try creating random forest model from training data
## 
## Call:
##  randomForest(formula = field.tree.canopy.symptoms ~ ., data = training,      ntree = 2001, importance = TRUE, proximity = TRUE, na.action = na.omit) 
##                Type of random forest: classification
##                      Number of trees: 2001
## No. of variables tried at each split: 23
## 
##         OOB estimate of  error rate: 26.92%
## Confusion matrix:
##           Healthy Unhealthy class.error
## Healthy       222        81   0.2673267
## Unhealthy      70       188   0.2713178

##     left daughter right daughter                                  split var
## 1               2              3                                    NFFD_at
## 2               4              5                                norm_Eref08
## 3               6              7                                      PPT05
## 4               8              9                      component_taxgrtgroup
## 5              10             11                                   DD_18_01
## 6               0              0                                       <NA>
## 7              12             13                                      RH_at
## 8              14             15            field.optional...slope.position
## 9               0              0                                       <NA>
## 10             16             17                                 norm_CMI03
## 11             18             19                               norm_NFFD_at
## 12             20             21                                 norm_CMI12
## 13             22             23                                norm_DD5_02
## 14             24             25 field.optional...site.location.description
## 15             26             27                       component_totalsub_r
## 16             28             29                                  norm_DD_0
## 17             30             31                                     DD5_05
## 18              0              0                                       <NA>
## 19             32             33                              component_weg
## 20             34             35                      muaggatt_slopegradwta
## 21             36             37            field.optional...site.hydrology
## 22             38             39                                     PPT_at
## 23             40             41                               PNWSRTMDEM.x
## 24             42             43                                      CMI06
## 25              0              0                                       <NA>
## 26             44             45                       component_totalsub_h
## 27             46             47                                 norm_PPT09
## 28              0              0                                       <NA>
## 29             48             49                                     Tmin10
## 30             50             51                                norm_Tmin04
## 31              0              0                                       <NA>
## 32             52             53                            component_ffd_l
## 33              0              0                                       <NA>
## 34             54             55                                      CMI04
## 35             56             57                 field.optional...tree.size
## 36             58             59                                     Tave12
## 37              0              0                                       <NA>
## 38              0              0                                       <NA>
## 39             60             61                                     CMI_at
## 40              0              0                                       <NA>
## 41             62             63                                norm_Tmax11
## 42              0              0                                       <NA>
## 43              0              0                                       <NA>
## 44             64             65                                      CMI09
## 45             66             67                                      PPT06
## 46              0              0                                       <NA>
## 47             68             69                                      PPT01
## 48              0              0                                       <NA>
## 49             70             71                                   norm_CMD
## 50              0              0                                       <NA>
## 51             72             73                               norm_Tmax_wt
## 52              0              0                                       <NA>
## 53              0              0                                       <NA>
## 54             74             75                              Profilecurv.x
## 55             76             77                                       eFFP
## 56             78             79                   component_slopelenusle_r
## 57              0              0                                       <NA>
## 58              0              0                                       <NA>
## 59              0              0                                       <NA>
## 60              0              0                                       <NA>
## 61              0              0                                       <NA>
## 62              0              0                                       <NA>
## 63              0              0                                       <NA>
## 64             80             81                                     DD5_04
## 65             82             83                                      RH_sp
## 66             84             85                                norm_Eref05
## 67             86             87                                norm_Tmin08
## 68              0              0                                       <NA>
## 69             88             89                              Tangentialc.x
## 70              0              0                                       <NA>
## 71             90             91                                   DD_18_05
## 72              0              0                                       <NA>
## 73             92             93                                norm_CMI_at
## 74             94             95                                    Eref_sm
## 75             96             97                       component_totalsub_r
## 76              0              0                                       <NA>
## 77              0              0                                       <NA>
## 78              0              0                                       <NA>
## 79              0              0                                       <NA>
## 80             98             99                                    Tmax_at
## 81            100            101                                     Tmax08
## 82            102            103                                   DD_18_02
## 83            104            105                                norm_DD5_11
## 84              0              0                                       <NA>
## 85              0              0                                       <NA>
## 86            106            107                 field.optional...tree.size
## 87              0              0                                       <NA>
## 88            108            109                               norm_NFFD_wt
## 89              0              0                                       <NA>
## 90            110            111                                      CMI11
## 91              0              0                                       <NA>
## 92            112            113                         component_corsteel
## 93              0              0                                       <NA>
## 94            114            115                                norm_CMI_wt
## 95            116            117                         component_irrcapcl
## 96              0              0                                       <NA>
## 97              0              0                                       <NA>
## 98            118            119                                     DD5_09
## 99            120            121                                     PPT_wt
## 100             0              0                                       <NA>
## 101             0              0                                       <NA>
## 102             0              0                                       <NA>
## 103             0              0                                       <NA>
## 104             0              0                                       <NA>
## 105           122            123                                norm_Tmin09
## 106             0              0                                       <NA>
## 107           124            125                                norm_DD5_07
## 108             0              0                                       <NA>
## 109           126            127                               norm_Eref_at
## 110             0              0                                       <NA>
## 111             0              0                                       <NA>
## 112           128            129                                     Eref04
## 113             0              0                                       <NA>
## 114           130            131                                     Tmax10
## 115             0              0                                       <NA>
## 116             0              0                                       <NA>
## 117           132            133                                   norm_SHM
## 118             0              0                                       <NA>
## 119           134            135                                      PPT02
## 120             0              0                                       <NA>
## 121             0              0                                       <NA>
## 122           136            137                                norm_CMI_sm
## 123             0              0                                       <NA>
## 124             0              0                                       <NA>
## 125             0              0                                       <NA>
## 126             0              0                                       <NA>
## 127             0              0                                       <NA>
## 128           138            139                                     Tave06
## 129             0              0                                       <NA>
## 130           140            141                                norm_DD5_sp
## 131             0              0                                       <NA>
## 132           142            143                       muaggatt_brockdepmin
## 133             0              0                                       <NA>
## 134             0              0                                       <NA>
## 135             0              0                                       <NA>
## 136             0              0                                       <NA>
## 137             0              0                                       <NA>
## 138           144            145                                     DD5_09
## 139           146            147                                 norm_CMD09
## 140             0              0                                       <NA>
## 141           148            149                      component_albedodry_l
## 142             0              0                                       <NA>
## 143             0              0                                       <NA>
## 144             0              0                                       <NA>
## 145             0              0                                       <NA>
## 146           150            151                                      CMI08
## 147           152            153                       component_totalsub_r
## 148           154            155                                      CMI01
## 149             0              0                                       <NA>
## 150           156            157                                  norm_DD18
## 151             0              0                                       <NA>
## 152             0              0                                       <NA>
## 153             0              0                                       <NA>
## 154             0              0                                       <NA>
## 155             0              0                                       <NA>
## 156             0              0                                       <NA>
## 157             0              0                                       <NA>
##       split point status prediction
## 1    8.450000e+01      1       <NA>
## 2    1.125000e+02      1       <NA>
## 3    4.800000e+01      1       <NA>
## 4    2.001079e+14      1       <NA>
## 5    4.460000e+02      1       <NA>
## 6    0.000000e+00     -1  Unhealthy
## 7    7.350000e+01      1       <NA>
## 8    1.304000e+03      1       <NA>
## 9    0.000000e+00     -1    Healthy
## 10   8.085000e+00      1       <NA>
## 11   6.150000e+01      1       <NA>
## 12   1.655000e+01      1       <NA>
## 13   5.650000e+01      1       <NA>
## 14   2.400000e+01      1       <NA>
## 15   7.499997e+01      1       <NA>
## 16   6.750000e+01      1       <NA>
## 17   2.945000e+02      1       <NA>
## 18   0.000000e+00     -1  Unhealthy
## 19   6.500000e+00      1       <NA>
## 20   3.400000e+01      1       <NA>
## 21   4.000000e+00      1       <NA>
## 22   3.350000e+02      1       <NA>
## 23   2.700000e+01      1       <NA>
## 24  -2.935000e+00      1       <NA>
## 25   0.000000e+00     -1  Unhealthy
## 26   3.599999e+01      1       <NA>
## 27   4.450000e+01      1       <NA>
## 28   0.000000e+00     -1  Unhealthy
## 29   6.950000e+00      1       <NA>
## 30   3.450000e+00      1       <NA>
## 31   0.000000e+00     -1    Healthy
## 32   9.500000e+01      1       <NA>
## 33   0.000000e+00     -1  Unhealthy
## 34   3.955000e+00      1       <NA>
## 35   6.000000e+00      1       <NA>
## 36   4.550000e+00      1       <NA>
## 37   0.000000e+00     -1    Healthy
## 38   0.000000e+00     -1    Healthy
## 39   1.865000e+01      1       <NA>
## 40   0.000000e+00     -1    Healthy
## 41   1.095000e+01      1       <NA>
## 42   0.000000e+00     -1  Unhealthy
## 43   0.000000e+00     -1    Healthy
## 44   5.335000e+00      1       <NA>
## 45   5.250000e+01      1       <NA>
## 46   0.000000e+00     -1  Unhealthy
## 47   1.310000e+02      1       <NA>
## 48   0.000000e+00     -1  Unhealthy
## 49   3.255000e+02      1       <NA>
## 50   0.000000e+00     -1    Healthy
## 51   7.250000e+00      1       <NA>
## 52   0.000000e+00     -1  Unhealthy
## 53   0.000000e+00     -1    Healthy
## 54   4.400442e-03      1       <NA>
## 55   3.295000e+02      1       <NA>
## 56   8.620339e+01      1       <NA>
## 57   0.000000e+00     -1    Healthy
## 58   0.000000e+00     -1  Unhealthy
## 59   0.000000e+00     -1    Healthy
## 60   0.000000e+00     -1  Unhealthy
## 61   0.000000e+00     -1    Healthy
## 62   0.000000e+00     -1  Unhealthy
## 63   0.000000e+00     -1    Healthy
## 64   1.395000e+02      1       <NA>
## 65   6.850000e+01      1       <NA>
## 66   1.000000e+02      1       <NA>
## 67   1.215000e+01      1       <NA>
## 68   0.000000e+00     -1  Unhealthy
## 69  -5.707497e-04      1       <NA>
## 70   0.000000e+00     -1  Unhealthy
## 71   1.340000e+02      1       <NA>
## 72   0.000000e+00     -1    Healthy
## 73   5.258000e+01      1       <NA>
## 74   4.095000e+02      1       <NA>
## 75   7.499997e+01      1       <NA>
## 76   0.000000e+00     -1  Unhealthy
## 77   0.000000e+00     -1    Healthy
## 78   0.000000e+00     -1    Healthy
## 79   0.000000e+00     -1  Unhealthy
## 80   1.490000e+01      1       <NA>
## 81   2.490000e+01      1       <NA>
## 82   4.135000e+02      1       <NA>
## 83   2.250000e+01      1       <NA>
## 84   0.000000e+00     -1  Unhealthy
## 85   0.000000e+00     -1    Healthy
## 86   1.400000e+01      1       <NA>
## 87   0.000000e+00     -1    Healthy
## 88   5.750000e+01      1       <NA>
## 89   0.000000e+00     -1    Healthy
## 90   1.215500e+01      1       <NA>
## 91   0.000000e+00     -1    Healthy
## 92   2.000000e+00      1       <NA>
## 93   0.000000e+00     -1    Healthy
## 94   4.163500e+01      1       <NA>
## 95   2.927692e+00      1       <NA>
## 96   0.000000e+00     -1  Unhealthy
## 97   0.000000e+00     -1    Healthy
## 98   3.065000e+02      1       <NA>
## 99   4.200000e+02      1       <NA>
## 100  0.000000e+00     -1  Unhealthy
## 101  0.000000e+00     -1    Healthy
## 102  0.000000e+00     -1    Healthy
## 103  0.000000e+00     -1  Unhealthy
## 104  0.000000e+00     -1    Healthy
## 105  8.450000e+00      1       <NA>
## 106  0.000000e+00     -1  Unhealthy
## 107  3.885000e+02      1       <NA>
## 108  0.000000e+00     -1    Healthy
## 109  1.275000e+02      1       <NA>
## 110  0.000000e+00     -1    Healthy
## 111  0.000000e+00     -1  Unhealthy
## 112  7.750000e+01      1       <NA>
## 113  0.000000e+00     -1  Unhealthy
## 114  1.570000e+01      1       <NA>
## 115  0.000000e+00     -1  Unhealthy
## 116  0.000000e+00     -1  Unhealthy
## 117  1.127500e+02      1       <NA>
## 118  0.000000e+00     -1    Healthy
## 119  1.820000e+02      1       <NA>
## 120  0.000000e+00     -1    Healthy
## 121  0.000000e+00     -1  Unhealthy
## 122  1.345000e+00      1       <NA>
## 123  0.000000e+00     -1  Unhealthy
## 124  0.000000e+00     -1    Healthy
## 125  0.000000e+00     -1  Unhealthy
## 126  0.000000e+00     -1  Unhealthy
## 127  0.000000e+00     -1    Healthy
## 128  1.555000e+01      1       <NA>
## 129  0.000000e+00     -1    Healthy
## 130  5.305000e+02      1       <NA>
## 131  0.000000e+00     -1    Healthy
## 132  1.363855e+02      1       <NA>
## 133  0.000000e+00     -1    Healthy
## 134  0.000000e+00     -1  Unhealthy
## 135  0.000000e+00     -1    Healthy
## 136  0.000000e+00     -1  Unhealthy
## 137  0.000000e+00     -1    Healthy
## 138  3.195000e+02      1       <NA>
## 139  4.600000e+01      1       <NA>
## 140  0.000000e+00     -1    Healthy
## 141  1.889381e-01      1       <NA>
## 142  0.000000e+00     -1  Unhealthy
## 143  0.000000e+00     -1    Healthy
## 144  0.000000e+00     -1  Unhealthy
## 145  0.000000e+00     -1    Healthy
## 146 -1.161500e+01      1       <NA>
## 147  8.999996e+00      1       <NA>
## 148  1.193500e+01      1       <NA>
## 149  0.000000e+00     -1    Healthy
## 150  2.215000e+02      1       <NA>
## 151  0.000000e+00     -1  Unhealthy
## 152  0.000000e+00     -1  Unhealthy
## 153  0.000000e+00     -1    Healthy
## 154  0.000000e+00     -1    Healthy
## 155  0.000000e+00     -1  Unhealthy
## 156  0.000000e+00     -1    Healthy
## 157  0.000000e+00     -1  Unhealthy
Visualize sample tree

Fit a single recursive partitioning or classification tree. Followed instructions from this youtube video.

Below is an example of one of the trees included in the random forest.

Troubleshooting

Error in randomForest.default(m, y, …) : Need at least two classes to do classification.

I may be misunderstanding this error, but I think it is referring to the response variable?

The documentation here describes the error prompt when: if (classRF && !addclass && length(unique(y)) < 2) stop(“Need at least two classes to do classification.”)

It is possible some of the NA or -9999 values are causing issues.

We can try imputing the data, however this requires us to remove columns with more than 53 factors, which probably makes sense anyway.

Removing factors with more than 53 levels didn’t resolve the error from the randomForest command, but it did allow us to use the rfImpute command to impute our data.

Wow it actually worked if the data is imputed.